<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="main_form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户信息表</label>
        <button type="button" class="layui-btn layui-btn-normal" id="upload-choose">选择文件</button>
        <a href="/pts/data/用户导入模板.xlsx" target="_blank" >
            <ins>下载模板文件</ins>
        </a>
    </div>
    

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../../js/common.js?v=1.0.4?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'tableSelect', 'upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            upload = layui.upload;

        // 渲染
        upload.render({
            elem: '#upload-choose',
            accept: 'file',
            exts: 'xlsx|xls',
            url: serverApiUrl + '/auth/add_users', // 此处配置你自己的上传接口即可
            headers: {'Authorization': 'Bearer ' + localStorage.getItem(tokenKey)},
            data: {
                /*
                device_type: function(){
                    return $('input[name="device_type"]:checked').val();;
                },
                */
            },
            size: 10240, // 限制文件大小，单位 KB
            multiple: false,
            number: 1,
            auto: false,
            bindAction: '#saveBtn',
            done: function(res) {
                console.log(res);
                if(res.data.code == 0 && res.data.success == true){
                    layer.msg('上传成功');

                    parent.layui.table.reload('currentTableId'); // 刷新父页面的表格数据
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                } else {
                    layer.msg(res.data.msg);
                }
            },
            error: function(index, upload){ // 错误回调
                layer.msg('上传失败');
            }
        });

        
    });
</script>
</body>
</html>